import { Controller, Get, Post, Body, Patch, Param, Delete, Query, Req } from '@nestjs/common'
import { HouseResService } from './house-res.service'
import { BaseController } from '@/base/base.controller'
import { HouseRes, RentModel } from '@prisma/client'
import { HouseResDto } from './dto/house-res.dto'
import { ApiTags } from '@nestjs/swagger'
import { RedisService } from '@/redis/redis.service'
import { LvAuth } from '@/decorator/auth.decorator'

@ApiTags('房源')
@Controller('house-res')
export class HouseResController extends BaseController<HouseRes, HouseResDto> {
  constructor(private readonly houseResService: HouseResService, private readonly redisService: RedisService) {
    super(houseResService)
  }

  @LvAuth('LANDLORD', 'VIPLANDLORD')
  @Post('add')
  async addHouseRes(@Body() dto: HouseResDto) {
    return await this.houseResService.addHouseRes(dto)
  }

  @Get('geoSearch')
  async geoSearch(
    @Query('longitude') longitude: string,
    @Query('latitude') latitude: string,
    @Query('radius') radius: string,
  ) {
    return await this.redisService.geoSearch([Number.parseFloat(longitude), Number.parseFloat(latitude)], +radius)
  }

  @Get('filter')
  async getHouseResFilter(
    @Query('page') page: string,
    @Query('house_peace') house_peace: string,
    @Query('house_use') house_use: string,
    @Query('min_rent') min_rent: string,
    @Query('max_rent') max_rent: string,
    @Query('house_type') house_type: string,
  ) {
    return await this.houseResService.getHouseResFilter(+page, house_peace, house_use, min_rent, max_rent, house_type)
  }

  @Get('search')
  async searchHouseResByName(@Query('page') page: string, @Query('house_plot') house_plot: string) {
    return await this.houseResService.searchHouseResByName(+page, house_plot)
  }

  @Get('detail/:id')
  async getHouseResDetail(@Param('id') id: string) {
    return await this.houseResService.getHouseResDetail(id)
  }

  @Patch('status/:id')
  async changeResStatus(@Param('id') id: string, @Body() dto: { house_status: boolean }) {
    return await this.houseResService.changeResStatus(id, dto.house_status)
  }

  @Get('mode')
  async getHouseResMode(@Query('page') page: string, @Query('house_mode') house_mode: RentModel) {
    return await this.houseResService.getHouseResMode(+page, house_mode)
  }

  @Delete('del/:id/:house_plot')
  async delHouseRes(@Param('id') id: string, @Param('house_plot') house_plot: string) {
    return await this.houseResService.delHouseRes(id, house_plot)
  }

  @Patch('edit/:id')
  async editHouseRes(@Param('id') id: string, @Body() dto: HouseResDto) {
    return await this.houseResService.editHouseRes(id, dto)
  }

  @Get('admin')
  async getHouseAdmin(@Query('page') page: string, @Query('landload_id') landload_id: string) {
    return await this.houseResService.getHouseAdmin(+page, landload_id)
  }
}
